#ifndef ALGORITHMS_ARRAYLIST_H
#define ALGORITHMS_ARRAYLIST_H
#include "../linearList/LinearList.h"
#include <algorithm>
#include "ArrayIterator.h"
#include <iterator>
using namespace std;
template<class T>
class ArrayIterator;
template <class T>
class ArrayList:public LinearList<T>{
public:
    explicit ArrayList(int initCapacity = 10);
    ArrayList(const ArrayList<T>&);
    ~ArrayList(){
        delete[] element;
    }
    //adt
    bool empty() const{
        return listSize == 0;
    }
    int size() const{
        return listSize;
    }
    T& get(int theIndex) const;
    int indexOf(const T& theElement) const;
    void erase(int theIndex);
    void insert(int theIndex,const T& theElement);
    void output(ostream& out) const;
    void push_back(const T& theElement);
    void clear();
    void set(int theIndex,const T& theElement);
    void reSize(int theSize);
    int capacity() const {
        return arrayLength;
    }
    ArrayIterator<T> begin(){
        return ArrayIterator<T>(element);
    }
    ArrayIterator<T> end(){
        return ArrayIterator<T>(element+listSize);
    }

protected:
    void checkIndex(int theIndex) const;
    T* element;
    int arrayLength;
    int listSize;
};
#endif //ALGORITHMS_ARRAYLIST_H
